package edu.uwm.cs552;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;

public enum Barrier {
	BLOCK, INLET, RIVER, DRAWN;
	
	public void draw(Graphics g, HexEdge e, double scale, boolean force) {
		if (!force && this != DRAWN) return; // draw nothing
		float width = (float)(scale/10);
		switch (this) {
		case BLOCK: g.setColor(Color.BLACK); width *= 2; break;
		case INLET: g.setColor(Terrain.WATER_COLOR); width *= 2; break;
		default: g.setColor(Color.BLUE); break;
		}
		Graphics2D g2 = (Graphics2D)g;
		Stroke savedStroke = g2.getStroke();
		g2.setStroke(getStroke(width));
		e.draw(g2, scale);
		g2.setStroke(savedStroke);
	}
	
	private Stroke savedStroke;
	private float savedSize = 0;
	private Stroke getStroke(float size) {
		if (size != savedSize) {
			savedStroke = new BasicStroke(size, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
			savedSize = size;
		}
		return savedStroke;
	}
}
